from PIL import Image
from torch.utils.tensorboard import SummaryWriter
import numpy as np
"""
TensorBoard 可视化面板 常见的api
    - add_scalar 添加序列
    - add_image 添加一张图片  参数类型如果是 array ，则需要指定 dataformats  步长也可以使用
    - add_images 添加一组图片
"""
writer = SummaryWriter("logs02")
image_path = "../dataset/train/ants/0013035.jpg"
img = Image.open(image_path)
# img.show()
img_array = np.array(img)
print(img_array.shape)

#写一张图片
writer.add_image("img" , img_array , dataformats="HWC")

#y = 2x
for i in range(120):
    #写一个序列
    writer.add_scalar("y=2x" , 2*i , i)

#关闭流
writer.close()

# 查看tensorboard
# tensorboard --logdir=demo02/logs02